import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { DemoEjsController } from './demo-ejs.controller';
import { Article } from './article.entity';
import { Policy } from './casbin/policy.entity';
import { Menu } from './menu/menu.entity';
import { User } from './user/user.entity';
import { ArticleService } from './article.service';
import { AuthModule } from './auth/auth.module';
import { LoginController } from './auth/login.controller';
import { DemoJwtController } from './auth/demo-jwt.controller';
import { UnauthorizedFilter } from './auth/unauthorized.filter';
import { CasbinModule } from './casbin/casbin.module';
import { CasbinController } from './casbin/casbin.controller';
import { MenuModule } from './menu/menu.module';
import { UserModule } from './user/user.module';
import { Category } from './category/category.entity';
import { CategoryModule } from './category/category.module';
import { Article as ArticleEntity } from './article/article.entity';
import { ArticleModule } from './article/article.module';
import { DataTemplate } from './data/data-template.entity';
import { DataRecord } from './data/data-record.entity';
import { DataModule } from './data/data.module';
import { SiteConfig } from './config/config.entity';
import { ConfigModule } from './config/config.module';
import { CasbinRole } from './casbin/role.entity';
import { APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core';
import { ResponseInterceptor } from './common/interceptors/response.interceptor';
import { AuthExceptionFilter } from './common/filters/auth-exception.filter';
import { JwtRefreshInterceptor } from './auth/jwt-refresh.interceptor';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: '127.0.0.1',
      port: 3306,
      username: 'root',
      password: '123456',
      database: 'nestjs',
      entities: [Article, Policy, Menu, User, Category, ArticleEntity, DataTemplate, DataRecord, SiteConfig, CasbinRole],
      synchronize: true,
    }),
    TypeOrmModule.forFeature([Article, Policy]),
    AuthModule,
    CasbinModule,
    MenuModule,
    UserModule,
    CategoryModule,
    ArticleModule,
    DataModule,
    ConfigModule,
  ],
  controllers: [AppController, DemoEjsController, LoginController, DemoJwtController, CasbinController],
  providers: [
    AppService, 
    ArticleService,
    {
      provide: APP_FILTER,
      useClass: AuthExceptionFilter,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: ResponseInterceptor,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: JwtRefreshInterceptor,
    },
  ],
})

export class AppModule {}